import React from 'react';
import ReactDOM from 'react-dom';

import { Provider } from 'mobx-react';
import { createHashHistory } from 'history';
import { Router, Route, useRouterHistory } from 'react-router';
import { syncHistoryWithStore, RouterStore } from 'mobx-react-router';
import { WeaDebugRouteMenu } from 'ecCom';

import { store, Login, Theme } from './index';

const routing = new RouterStore();
const allStore = { routing, ...store };

const browserHistory = useRouterHistory(createHashHistory)({
  queryKey: '_key',
  basename: '/',
});

const history = syncHistoryWithStore(browserHistory, routing);
window.weaHistory = history;

const Root = () => (
  <Provider {...allStore}>
    <Router history={history}>
      <Route path="/" component={WeaDebugRouteMenu}>
        <Route path="login" component={Login} />
        <Route path="main" component={Theme} />
      </Route>
    </Router>
  </Provider>
);

ReactDOM.render(<Root />, document.getElementById('container'));
